//
//  JWGRNewIDVC.m
//  koubei
//
//  Created by 李彦宏 on 2018/4/25.
//  Copyright © 2018年 朱圳. All rights reserved.
//

#import "JWGRNewIDVC.h"
#import "JWGRIDNewcell.h"
#import "JWGREditorPic.h"//查看图片上传图片
#import "JWGRUsermodel.h"
#import "JWUserManager.h"
#import "UIImageView+WebCache.h"

@interface JWGRNewIDVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *IDCounts;
@property (nonatomic, strong) JWGRUsermodel *Gmodel;


//***********8张图片*************//

@property (nonatomic, strong) NSString *picid;

@property (nonatomic, strong) NSString *picid1;
@property (nonatomic, strong) NSString *url1;
@property (nonatomic, strong) NSString *picid2;
@property (nonatomic, strong) NSString *url2;
@property (nonatomic, strong) NSString *picid3;
@property (nonatomic, strong) NSString *url3;
@property (nonatomic, strong) NSString *picid4;
@property (nonatomic, strong) NSString *url4;
@property (nonatomic, strong) NSString *picid5;
@property (nonatomic, strong) NSString *url5;
@property (nonatomic, strong) NSString *picid6;
@property (nonatomic, strong) NSString *url6;
@property (nonatomic, strong) NSString *picid7;
@property (nonatomic, strong) NSString *url7;
@property (nonatomic, strong) NSString *picid8;
@property (nonatomic, strong) NSString *url8;
@end

@implementation JWGRNewIDVC

#pragma -mark ———————————加载对应研究生的数据——————————————————
-(void)setGRdata{
    if(self.Gmodel.ID==nil){
        self.Gmodel.ID=self.Gmodel.gid;
    }
    NSDictionary *dic=@{
                        @"jwid":JWid,
                        @"jwpassword":JWpassword,
                        @"pid":self.Gmodel.ID,
                        };
    [[AFNetworkTool shareManager]postJSONWithUrl:JW_SeeGRPic parmas:dic successData:^(id json) {
        NSArray *arry=json[@"imglist"];
        for(int i=0;i<arry.count;i++){
            if ([arry[i][@"position"] isEqualToString:@"1"]) {
                self.picid1 = arry[i][@"id"];
                self.url1 = arry[i][@"url"];
            }
            if ([arry[i][@"position"] isEqualToString:@"2"]) {
                self.picid2 = arry[i][@"id"];
                self.url2 = arry[i][@"url"];
            }
            if ([arry[i][@"position"] isEqualToString:@"3"]) {
                self.picid3 = arry[i][@"id"];
                self.url3 = arry[i][@"url"];
            }
            if ([arry[i][@"position"] isEqualToString:@"4"]) {
                self.picid4 = arry[i][@"id"];
                self.url4 = arry[i][@"url"];
            }
            if ([arry[i][@"position"] isEqualToString:@"5"]) {
                self.picid5 = arry[i][@"id"];
                self.url5 = arry[i][@"url"];
            }
            if ([arry[i][@"position"] isEqualToString:@"6"]) {
                self.picid6 = arry[i][@"id"];
                self.url6 = arry[i][@"url"];
            }
            if ([arry[i][@"position"] isEqualToString:@"7"]) {
                self.picid7 = arry[i][@"id"];
                self.url7 = arry[i][@"url"];
            }
            if ([arry[i][@"position"] isEqualToString:@"8"]) {
                self.picid8 = arry[i][@"id"];
                self.url8 = arry[i][@"url"];
            }
        }
        __weak typeof(self) weakslf = self;
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [weakslf.tableView reloadData];
            
        });
        
        
    } failure:^(NSError *error) {
        NSLog(@"--error--%@", error);
        
    }];
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [EasyShowOptions sharedEasyShowOptions].lodingShowType =  LodingShowTypeTurnAround ;
    [EasyShowOptions sharedEasyShowOptions].textStatusType =  ShowTextStatusTypeStatusBar ;
    [EasyShowLodingView showLodingText:@""];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
       [self setGRdata];
        [EasyShowLodingView hidenLoding];
    });
    

}

- (void)viewDidLoad
{
    [super viewDidLoad];
   [self.view addSubview:self.tableView];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    self.Gmodel=[JWUserManager Gme];
    //@"入学证明正面",@"入学证明反面",@"录取通知正面",@"录取通知反面",@"校园卡正面",@"校园卡反面",
    _IDCounts=[NSMutableArray arrayWithObjects:@"研究生证明一",@"研究生证明二", nil];
    // Do any additional setup after loading the view.
}

#pragma -mark -----------------------------tableview datasource and delegate---------------------------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _IDCounts.count;
}

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 50;
//}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JWGRIDNewcell *cell=[JWGRIDNewcell cellwithTableview:tableView];
    cell.IDNameLb.text=_IDCounts[indexPath.row];
    switch (indexPath.row) {
        case 0:
            [self UImageV:cell.IDpicView imageUrl:self.url1];
            break;
        case 1:
            [self UImageV:cell.IDpicView imageUrl:self.url2];
            break;
//        case 2:
//            [self UImageV:cell.IDpicView imageUrl:self.url3];
//            break;
//        case 3:
//            [self UImageV:cell.IDpicView imageUrl:self.url4];
//            break;
//        case 4:
//            [self UImageV:cell.IDpicView imageUrl:self.url5];
//            break;
//        case 5:
//            [self UImageV:cell.IDpicView imageUrl:self.url6];
//            break;
//        case 6:
//            [self UImageV:cell.IDpicView imageUrl:self.url7];
//            break;
//        case 7:
//            [self UImageV:cell.IDpicView imageUrl:self.url8];
//            break;
        
        default:
            
            break;
    }
    

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    JWGREditorPic *vc=[[JWGREditorPic alloc]init];
   
    vc.title=_IDCounts[indexPath.row];
    switch (indexPath.row) {
        case 0:
            vc.picid=self.picid1;
            vc.position=@"1";
            vc.picUrl=self.url1;
            break;
        case 1:
            vc.picid=self.picid2;
            vc.position=@"2";
            vc.picUrl=self.url2;
            break;
//        case 2:
//            vc.picid=self.picid3;
//            vc.position=@"3";
//            vc.picUrl=self.url3;
//            break;
//        case 3:
//            vc.picid=self.picid4;
//            vc.position=@"4";
//            vc.picUrl=self.url4;
//            break;
//        case 4:
//            vc.picid=self.picid5;
//            vc.position=@"5";
//            vc.picUrl=self.url5;
//            break;
//        case 5:
//            vc.picid=self.picid6;
//            vc.position=@"6";
//            vc.picUrl=self.url6;
//            break;
//        case 6:
//            vc.picid=self.picid7;
//            vc.position=@"7";
//            vc.picUrl=self.url7;
//            break;
//        case 7:
//            vc.picid=self.picid8;
//            vc.position=@"8";
//            vc.picUrl=self.url8;
//            break;
        default:
            break;
    }
    
    
    
     [self.navigationController pushViewController:vc animated:YES];
    

}

-(void)UImageV:(UIImageView *)UImageV imageUrl:(NSString *)imageUrl{
    
    NSString *str=[NSString stringWithFormat:@"%@%@",ImageBaseURL,imageUrl];
    NSLog(@"--str--%@", str);
    str=[str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    NSURL *url=[NSURL URLWithString:str];
    NSLog(@"--url--%@", url);
    UIImage *placeholder=[UIImage imageNamed:@"NoData"];
    [UImageV sd_setImageWithURL:url placeholderImage:placeholder];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(UITableView *)tableView{
    if(_tableView==nil){
        _tableView=[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        //隐藏组距导航栏的间距
        _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
        _tableView.backgroundColor=[UIColor whiteColor];
        _tableView.showsHorizontalScrollIndicator=NO;
        _tableView.showsVerticalScrollIndicator=NO;
        _tableView.dataSource=self;
        _tableView.delegate=self;
        _tableView.rowHeight=50;
        _tableView.tableFooterView=[[UIView alloc]init];
    _tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    }
    return _tableView;
}


@end
